package com.salt.admin.api.feign.hystrix;

import com.salt.admin.api.feign.client.MenuClient;
import com.salt.admin.api.model.Menu;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description 菜单（后台管理中心）远程调用失败处理类
 * @Author salt
 * @Date 2020/8/18 16:40
 * @Version 1.0
 */
@Slf4j
@Component
public class MenuClientHystrix implements FallbackFactory<MenuClient> {

    @Override
    public MenuClient create(Throwable throwable) {

        String message = throwable.getMessage() == null ?
                "No available server for client: ADMIN-CENTER" :
                throwable.getMessage();
        log.info("Hystrix:{}", message);

        return new MenuClient() {

            @Override
            public void saveMenu(Menu menu) {

                log.info("--保存菜单异常");
            }

            @Override
            public List<Menu> findAllMenu() {
                log.info("--查询菜单异常");
                return null;
            }
        };
    }
}
